var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "react", "mobile/services/memberService", "maishu-dilu", "mobile/site", "maishu-ui-toolkit", "react-dom"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    const React = require("react");
    const memberService_1 = require("mobile/services/memberService");
    const maishu_dilu_1 = require("maishu-dilu");
    const site_1 = require("mobile/site");
    const ui = require("maishu-ui-toolkit");
    const ReactDOM = require("react-dom");
    function default_1(page) {
        let member = page.createService(memberService_1.MemberService);
        let usernameInput;
        let passwordInput;
        let formElement;
        let validator;
        let returnString = (page.data.return || 'user_index');
        var jsx = React.createElement(React.Fragment, null,
            React.createElement("header", null, site_1.defaultNavBar(page, { title: "登录" })),
            React.createElement("section", null,
                React.createElement("form", { className: "form-horizontal container", ref: (e) => formElement = e || formElement },
                    React.createElement("div", { className: "form-group" },
                        React.createElement("div", { className: "col-xs-12" },
                            React.createElement("input", { type: "text", name: "username", className: "form-control", placeholder: "\u624B\u673A\u53F7\u7801", ref: (e) => usernameInput = e || usernameInput }))),
                    React.createElement("div", { className: "form-group" },
                        React.createElement("div", { className: "col-xs-12" },
                            React.createElement("input", { type: "password", name: "password", className: "form-control", placeholder: "\u5BC6\u7801", ref: (e) => passwordInput = e || passwordInput }))),
                    React.createElement("div", { className: "form-group" },
                        React.createElement("div", { className: "col-xs-12" },
                            React.createElement("button", { id: "Login", type: "button", className: "btn btn-primary btn-block", ref: (e) => {
                                    if (!e)
                                        return;
                                    e.onclick = ui.buttonOnClick(() => __awaiter(this, void 0, void 0, function* () {
                                        if (!validator) {
                                            validator = new maishu_dilu_1.FormValidator(formElement, { name: "username", rules: [maishu_dilu_1.rules.required(), maishu_dilu_1.rules.mobile()] }, { name: "password", rules: [maishu_dilu_1.rules.required()] });
                                        }
                                        if (!validator.check())
                                            return;
                                        yield member.login(usernameInput.value, passwordInput.value);
                                        page.app.showPage(returnString, {}, true);
                                    }));
                                } }, "\u7ACB\u5373\u767B\u5F55")),
                        React.createElement("div", { className: "col-xs-12 text-center", style: { marginTop: 10 } },
                            React.createElement("a", { href: "#user_register", className: "pull-left" }, "\u6211\u8981\u6CE8\u518C"),
                            React.createElement("a", { href: "#user_resetPassword", className: "pull-right" }, "\u5FD8\u8BB0\u5BC6\u7801"))))));
        ReactDOM.render(jsx, page.element);
    }
    exports.default = default_1;
});
